//
//  jiaViewController.m
//  模拟-百思不得姐
//
//  Created by 谭浔明 on 16/8/5.
//  Copyright © 2016年 chunyu. All rights reserved.
//

#import "jiaViewController.h"
#import "SharingViewController.h"
#import "GetFilePath.h"


@interface jiaViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>



@property (weak, nonatomic) IBOutlet UIButton *fashiping;
@property (weak, nonatomic) IBOutlet UIButton *fatuping;
@property (weak, nonatomic) IBOutlet UIButton *faduanzi;
@property (weak, nonatomic) IBOutlet UIButton *fashengyin;
@property (weak, nonatomic) IBOutlet UIButton *tie;
@property (weak, nonatomic) IBOutlet UIButton *fenxiang;
@property (weak, nonatomic) IBOutlet UIImageView *biaotupian;
@property (weak, nonatomic) IBOutlet UILabel *fa1;
@property (weak, nonatomic) IBOutlet UILabel *fa2;
@property (weak, nonatomic) IBOutlet UILabel *fa3;
@property (weak, nonatomic) IBOutlet UILabel *fa4;
@property (weak, nonatomic) IBOutlet UILabel *fa5;
@property (weak, nonatomic) IBOutlet UILabel *fa6;


@end

@implementation jiaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
 
}


- (void)viewWillAppear:(BOOL)animated
{

    [UIView animateWithDuration:1 animations:^{
        _fashiping.y += self.view.width;
        _fa1.y += self.view.width;
        
        _fatuping.y +=self.view.width;
        _fa2.y += self.view.width;

        _faduanzi.y +=self.view.width;
        _fa3.y += self.view.width;

        _fashengyin.y +=self.view.width;
        _fa4.y += self.view.width;

        _tie.y +=self.view.width;
        _fa5.y += self.view.width;

        _fenxiang.y +=self.view.width;
        _fa6.y += self.view.width;

        _biaotupian.y -=self.view.width;
         
        
    } completion:^(BOOL finished) {
        
    }];
}
//取消按钮
- (IBAction)cancel:(UIButton *)sender {
  
    [UIView animateWithDuration:1 animations:^{
    
        _fashiping.y += self.view.width;
        _fa1.y += self.view.width;
        
        _fatuping.y +=self.view.width;
        _fa2.y += self.view.width;
        
        _faduanzi.y +=self.view.width;
        _fa3.y += self.view.width;
        
        _fashengyin.y +=self.view.width;
        _fa4.y += self.view.width;
        
        _tie.y +=self.view.width;
        _fa5.y += self.view.width;
        
        _fenxiang.y +=self.view.width;
        _fa6.y += self.view.width;
        
        _biaotupian.y -=self.view.width;
        
        
        
        
    } completion:^(BOOL finished) {
        
    }];
    
    //延迟时间
    int64_t delayInSeconds = 0.9999999999999999999999999;
 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    printf("回到主页");
        UIView *v=[[UIView alloc]init];
        v.backgroundColor=[UIColor whiteColor];
        
        [self dismissViewControllerAnimated:YES completion:nil];
        
    
    });
}

- (IBAction)VideoBtn:(UIButton *)sender {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        picker.videoQuality = UIImagePickerControllerQualityTypeMedium; //录像质量
        picker.videoMaximumDuration = 600.0f; //录像最长时间
        picker.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前设备不支持录像功能" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }
    //跳转到拍摄页面
    [self presentViewController:picker animated:YES completion:nil];

    
    printf("视频");
}


- (IBAction)PictureBtn:(UIButton *)sender {
    
     
     //系统相册图片
     UIImagePickerController *picker = [[UIImagePickerController alloc] init];
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    
     [self presentViewController:picker animated:YES completion:nil];
    
    
}

//图片代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
//    _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
}



//拍摄完成后要执行的代理方法
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
//{
//    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
//    BOOL success;
//    NSFileManager *fileManager = [NSFileManager defaultManager];
//    if ([mediaType isEqualToString:@"public.image"]) {
//        //得到照片
//        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//            //图片存入相册
//            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
//        }
//        
//        NSString *imagePath = [GetFilePath getSavePathWithFileSuffix:@"png"];
//        success = [fileManager fileExistsAtPath:imagePath];
//        if (success) {
//            [fileManager removeItemAtPath:imagePath error:nil];
//        }
//        
//        NSData *imageData = UIImagePNGRepresentation(image);
//        [imageData writeToFile:imagePath atomically:YES]; //写入本地
//        success = [fileManager fileExistsAtPath:imagePath];
//        if (success) {
//            NSLog(@"图片写入成功,image路径:%@",imagePath);
//        }
//    } else if ([mediaType isEqualToString:@"public.movie"]) {
//        NSString *videoPath = [GetFilePath getSavePathWithFileSuffix:@"mov"];
//        success = [fileManager fileExistsAtPath:videoPath];
//        if (success) {
//            [fileManager removeItemAtPath:videoPath error:nil];
//        }
//        
//        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
//        NSData *videlData = [NSData dataWithContentsOfURL:videoURL];
//        [videlData writeToFile:videoPath atomically:YES]; //写入本地
//        //存储数据
//        success = [fileManager fileExistsAtPath:videoPath];
//        if (success) {
//            NSLog(@"media 写入成功,video路径:%@",videoPath);
//        }
//    }
//    [self dismissViewControllerAnimated:YES completion:nil];
//}

//进入拍摄页面点击取消按钮
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
